package com.tourlaid.mamagerment.service.impl

import com.tourlaid.mamagerment.dto.HomeDto
import com.tourlaid.mamagerment.entity.Thought
import com.tourlaid.mamagerment.mapper.ThoughtMapper
import com.tourlaid.mamagerment.service.ThoughtService
import com.tourlaid.mamagerment.util.LoginUtil
import org.springframework.stereotype.Service
import java.util.*
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/8.
 */
@Service("thoughtService")
class ThoughtServiceImpl : ThoughtService {
    override fun insertThought(content: String, fileNameList: List<String>) {
        var thought = Thought()
        thought.storeId = 5L
        thought.content = content.toString()
        thought.userId = LoginUtil.userId
        var i = 0
        for (item in fileNameList) {
            if (i == 0) {
                thought.imageOne = item
            } else if (i == 1) {
                thought.imageTwo = item
            } else if (i == 2) {
                thought.imageThree = item
            } else if (i == 3) {
                thought.imageFour = item
            } else if (i == 4) {
                thought.imageFive = item
            }
            i++
        }
        thought.creator = LoginUtil.userId
        thought.editor = LoginUtil.userId
        thoughtMapper!!.insert(thought)
    }

    override fun delete(id: Long) {
        thoughtMapper!!.delete(id, LoginUtil.userId)
    }

    @Resource
    var thoughtMapper: ThoughtMapper? = null

    override fun queryForList(integral: Int, startDate: Date): List<HomeDto>? {
        return thoughtMapper!!.queryForList(integral, startDate)
    }

    override fun getById(id: Long): Thought {
        return thoughtMapper!!.getById(id)
    }

    override fun queryByUserId(targetUserId: Long): List<Thought> {
        return thoughtMapper!!.queryByUserId(targetUserId)
    }

    override fun queryCountByStoreIdList(storeIdList: List<Long>): List<Map<String, Any>> {
        return thoughtMapper!!.queryCountByStoreIdList(storeIdList)
    }

    override fun queryByShoreId(storeId: Long): List<HomeDto>? {
        return thoughtMapper!!.queryByShoreId(storeId)
    }
}